import axios, { AxiosInstance } from "axios";

const isDev = process.env.NODE_ENV === 'development';

const myAxios: AxiosInstance = axios.create({
    baseURL: isDev ? 'http://127.0.0.1:8081/api' : 'https://gouhuo-backend.allbugs.top:8081/api',
});

myAxios.defaults.withCredentials = true; // 携带cookie

myAxios.interceptors.request.use(function (config) {
    // console.log('我要发请求啦', config)
    return config;
}, function (error) {
    return Promise.reject(error);
});

myAxios.interceptors.response.use(function (response) {
    // console.log('我收到你的响应啦', response.data)
    return response.data;
}, function (error) {
    return Promise.reject(error);
});

export default myAxios;
